/*
 * Created by Christopher King
 * Copyright (C) 2007 Christopher King, All Rights Reserved.
 */

package us.cirion.adventure.engine.prerequisite;

import java.util.Enumeration;

import us.cirion.adventure.engine.Noun;
import us.cirion.adventure.engine.Player;
import us.cirion.adventure.engine.PreRequisite;

/**
 * Requires that the player possesses the item.
 * 
 * @author Chris
 */
public class ItemInInventory implements PreRequisite
{

	private Noun item;
	private Player player;

	/**
	 * Constructs a new requirement that the player possess a certain item.
	 * 
	 * @param player The player who must hold the item.
	 * @param item The item that must be possessed.
	 */
	public ItemInInventory(Player player, Noun item)
	{
		this.item = item;
		this.player = player;
	}

	/**
	 * Indicates whether the player has the item.
	 * 
	 * @return <code>true</code> if the item is in the player's inventory,
	 *         <code>false</code> otherwise.
	 */
	public boolean isSatisfied()
	{
		Enumeration items = player.getItems();
		while (items.hasMoreElements())
		{
			if (items.nextElement().equals(item))
			{
				return true;
			}
		}
		return false;
	}

}
